<?php
	//Xay dung tim kiem
	$ssFilter 		= $this->arrParam['ssFilter'];
	$page = '';
	if(isset($this->arrParam['page'])){
		$page = '/page/' . $this->arrParam['page'];
	}
	$action_link 	= $this->baseUrl($this->currentController . '/filter/type/order');
	
	$lblName 		= $this->cmsLinkSort('Tên nhân viên','c.name_nhanvien',$ssFilter,$this->imgUrl . '/admin',$action_link);
	$lblPhongban 	= $this->cmsLinkSort('Thuộc phòng ban','c.name_phongban',$ssFilter,$this->imgUrl . '/admin',$action_link);
	$lblHdDongia 	= $this->cmsLinkSort('Đơn giá hợp đồng','c.hd_dongia',$ssFilter,$this->imgUrl . '/admin',$action_link);
	$lblHdThanhtien = $this->cmsLinkSort('Thành tiền sau KM','c.hd_thanhtien',$ssFilter,$this->imgUrl . '/admin',$action_link);
	$lblHdDadong 	= $this->cmsLinkSort('Số tiền đã thu','c.hd_sotiendadong',$ssFilter,$this->imgUrl . '/admin',$action_link);
	$lblKhNo	 	= $this->cmsLinkSort('Khách hàng còn nợ','c.hd_sotienno',$ssFilter,$this->imgUrl . '/admin',$action_link);
	

	$lblID 			= $this->cmsLinkSort('ID','c.id',$ssFilter,$this->imgUrl . '/admin',$action_link);

	$keywords = $this->formText('keywords',$ssFilter['keywords'],array('class'=>'txtshort txtsearch'));
	
// 	$optionsThang=array("0"=> '- Tất cả -',"01"=> 'Tháng 1',"02"=> 'Tháng 2',"03"=> 'Tháng 3',"04"=> 'Tháng 4',"05"=> 'Tháng 5',"06"=> 'Tháng 6',"07"=> 'Tháng 7',"08"=> 'Tháng 8',"09"=> 'Tháng 9',"10"=> 'Tháng 10',"11"=> 'Tháng 11',"12"=> 'Tháng 12');
	
// 	$date = new Zend_Date();
// 	$dateNamnay = $date->toString('YYYY');
// 	$dateNam = $dateNamnay;
// 	if(isset($ssFilter['date_nam'])) {
// 		$dateNam = $ssFilter['date_nam'];
// 	}
	
// 	$date = new Zend_Date();
// 	$dateThangnay = $date->toString('MM') ;
// 	if(isset($ssFilter['date_thang'])) {
// 		$dateThangnay = $ssFilter['date_thang'];
// 	}
	
// 	for ($i = 0; $i <= 10; $i++){
// 		$optionsNam[$dateNamnay-$i] = $dateNamnay-$i;
// 	}
// 	$linkSlbThang		 	= $this->baseUrl($this->currentController . '/filter/type/date_thang/' . $this->arrParam['date_thang']);
// 	$selectThang 			= $this->formSelect('date_thang',$dateThangnay,array('onchange'=>"OnSubmitForm('" .$linkSlbThang ."')"), $optionsThang);
// 	$linkSlbNam			 	= $this->baseUrl($this->currentController . '/filter/type/date_nam/' . $this->arrParam['date_nam']);
// 	$selectNam	 			= $this->formSelect('date_nam',$dateNam,array('onchange'=>"OnSubmitForm('" .$linkSlbNam ."')"), $optionsNam);
	
	
	
	
	$selectLanguages = $this->slbLanguages;
	$linkSlbLanguages = $this->baseUrl($this->currentController . '/filter/type/lang');
	$selectLanguages = $this->formSelect('lang_code',$ssFilter['lang_code'],array('onchange'=>"OnSubmitForm('" .$linkSlbLanguages ."')"),$selectLanguages);
	
	$linkSearch = $this->baseUrl($this->currentController . '/filter/type/search/key/1');
	$btnSearch = $this->formButton('search-now','Tìm',array('class' => 'btnsearch', 'onclick'=>"OnSubmitForm('" .$linkSearch . "')"));
	
	$linkResetSearch = $this->baseUrl($this->currentController . '/filter/type/search/key/0');
	$btnResetSearch = $this->formButton('clear-keywords','Xóa',array('class' => 'btnsearch', 'onclick'=>"OnSubmitForm('" .$linkResetSearch ."')"));
	
	$linkSlbPhongban 	= $this->baseUrl($this->currentController . '/filter/type/id_phongban/' . $this->arrParam['tn']);
	$selectPhongban 	= $this->cmsSelect('id_phongban', $ssFilter['id_phongban'], $this->slbPhongban, array('onchange'=>"OnSubmitForm('" .$linkSlbPhongban ."')"));
	
	$linkSlbNhanvien 	= $this->baseUrl($this->currentController . '/filter/type/id_nhanvien/' . $this->arrParam['tn']);
	$selectNhanvien 	= $this->formSelect('id_nhanvien', $ssFilter['id_nhanvien'], array('onchange'=>"OnSubmitForm('" .$linkSlbNhanvien ."')"), $this->slbNhanvien);
	
	$tungay = $this->formText('tungay',$ssFilter['tungay'],array('class'=>'txtshort txtsearch hasDatePicker ','style' => 'margin-left:3px; width:70px;','placeholder' => 'Từ ngày'));
	$denngay = $this->formText('denngay',$ssFilter['denngay'],array('class'=>'txtshort txtsearch hasDatePicker','style' => 'width:70px;','placeholder' => 'đến ngày'));
	
	
	$strSearch = $keywords . ' ' . $tungay . ' ' . $denngay . ' ' . $btnSearch . ' ' . $btnResetSearch;
	
	
	//$strSearchRight = $selectPhongban . ' ' . $selectNhanvien .' '. $selectNam .' '. $selectThang ;
	$strSearchRight = $selectPhongban . ' ' . $selectNhanvien  ;
?>

<div class="left_content">
	<?php echo $this->render($this->arrParam['controller'] . '/toolbar/left.php');?>
	
</div>
<?php 
// echo '<pre>';
// print_r($this->Items);
// echo '</pre>';

?>
<div class="right_content">
	<div class="appContent">
	<?php echo $this->render($this->arrParam['controller'] . '/toolbar/index.php');?>
		
	<form action="" method="post" name="appForm">
	 
	<div class="tblForm">
	
		
		<div class="formList goc5">
			<div class="appTop goct5">
				<div class="block_filter">
					<div class="fl">
						<div class="listSearch">
							<?php echo $strSearch; ?>
							<div class="clr"></div>			
						</div>
					</div>
					<div class="fr listSelect">
						<?php echo $strSearchRight;?>
					</div>
					<div class="clr"></div>
				</div>
			</div>
			<div class="appBody">
				<table class="tblList">
					<tr>
						<th><?php echo $lblName;?></th>
						<th><?php echo $lblPhongban;?></th>
						<th><?php echo $lblHdDongia;?></th>
						<th>Khuyến mại</th>
						<th>Thành tiền</th>
						<th><?php echo $lblHdDadong; ?></th>
						<th><?php echo $lblKhNo; ?></th>
						<th>ID Nhân viên</th>
						<th>Thao tác</th>
					</tr>
					
				<?php
					$date = new Zend_Date();
					$time= $date->get('dd-MM-YYYY');
					$hd_dongia =0;
					$hd_thanhtien =0;
					$hd_sotienno =0;
					$hd_sotiendadong =0;
					foreach ($this->Items as $key => $val){
						$id 				= $val['id'];
						$id_nhanvien 		= $val['id_nhanvien'];
						$name 				= $val['name_nhanvien'];
						$NamePhongBan		= $val['name_phongban'];
						$HdDongia			= $val['hd_dongia'];
						$hd_dongia			= $hd_dongia + $val['hd_dongia'];
						
						$HdThanhtien		= $val['hd_thanhtien'];
						$hd_thanhtien		= $hd_thanhtien + $val['hd_thanhtien'];
						
						$hd_khuyenmai		= $HdDongia-$HdThanhtien;
						
						$HdSotienno		 	= $val['hd_sotienno'];
						$hd_sotienno		= $hd_sotienno + $val['hd_sotienno'];
						$HdDadong		 	= $val['hd_sotiendadong'];
						$hd_sotiendadong	= $hd_sotiendadong + $val['hd_sotiendadong'];
						$user_name			= $val['user_name'];
	
						$linkInfo			= $this->baseUrl($this->currentController . '/info/id/' . $id . $page);
						$btnInfo			= $this->cmsIconButton('Xem thông tin', $this->imgUrl . '/admin/icon_info.png', $linkInfo);
						
						$linkEdit			= $this->baseUrl($this->currentController . '/edit/id/' . $id . $page);
						$btnEdit			= $this->cmsIconButton('Sửa', $this->imgUrl . '/admin/icon_edit.png', $linkEdit);
						
						$linkDelete			= $this->baseUrl($this->currentController . '/delete/id/' . $id . $page);
						$btnDelete			= $this->cmsIconButton('Xóa', $this->imgUrl . '/admin/publish_r.png', $linkDelete);
						
						$linkinfoDoanhthu 	= $this->baseUrl($this->currentController . '/info/id/' . $id_nhanvien);
						$linkinfoListHD		= $this->baseUrl('hopdong/admin-item/index/id_nhanvien/' . $id_nhanvien);
												
						$btnAdd				= $this->cmsIconButton('Tùy chọn', $this->imgUrl . '/menu/icon-16-maintenance.png', 'javascript::void(0)', array('onclick' => 'showFunction('. $id .')'));
						$divAdd				= 	'<div class="blockFunction selectFunction'.$id .'">
													<ul>
														<li><a href="'.$linkinfoListHD.'" class="icon-16-category">Danh sách hợp đồng</a></li>
														<li><a href="'.$linkinfoDoanhthu.'" class="icon-16-profit">Doanh thu nhân viên</a></li>
													</ul>
												</div>';
						$strIconButton 	=  $btnAdd .' '. $divAdd;
						
						$user_name		= '<p class="smallsub">(Tên đăng nhập: ' . $user_name . ' )</p>';
						$name 			= '<b><a href="javascript:void(0)">' . $name . '</a></b>' . $user_name;
					
						$cid 			= $this->formCheckbox('cid[]',$val['id']);
						
						$classRow = 'row1';
						if($key % 2 == 0)
							$classRow = 'row0';
				?>
					<tr class="<?php echo $classRow;?>">
						<td align="left"><?php echo $name;?></td>
						<td align="left"><?php echo $NamePhongBan;?></td>
						<td align="right"><span class="auto_numberic "><?php echo $HdDongia;?></span></td>
						<td align="right"><span class="auto_numberic "><?php echo $hd_khuyenmai;?></span></td>
						<td align="right"><span class="auto_numberic "><?php echo $HdThanhtien;?></span></td>
						<td align="right"><span class="auto_numberic "><?php echo $HdDadong;?></span></td>
						<td align="right"><span class="auto_numberic red"><?php echo $HdSotienno;?></span></td>
						<td align="center">NV<?php echo $id_nhanvien;?></td>
						<td align="center"><div style="position:relative"><?php echo $strIconButton;?></div></td>
					</tr>
				<?php
					} 
				?> 
				<?php /* ?>
				<tr>
					<td align="left"><a><b>Tổng Doanh Thu:</b></a></td>
					<td align="center"></td>
					<td align="right"><a><span class="auto_numberic" style="font-weight: bold;"><?php echo $hd_dongia;?></span></a></td>
					<td align="right"><a><span class="auto_numberic" style="font-weight: bold;"><?php echo $hd_thanhtien;?></span></a></td>
					<td align="right"><a><span class="auto_numberic" style="font-weight: bold;"><?php echo $hd_sotiendadong;?></span></a></td>
					<td align="right"><a><span class="auto_numberic" style="font-weight: bold;"><?php echo $hd_sotienno;?></span></a></td>
					<td align="center"></td>
					<td align="center"></td>
				</tr>
				<?php */ ?>
			</table>
			</div>
			<div class="appBottom">
				<div class="pagination">
					<?php
						$currentUrl = $this->baseUrl($this->currentController . '/index');
						echo $this->paginationControl($this->paginator,'Sliding','pagination.phtml',array('currentUrl'=>$currentUrl)); 
					?>
				</div>
			</div>
		</div>
	</div> 
	</form>
	</div>
</div>
<div class="clr"></div>	
<script type="text/javascript">
	function showFunction(i){
		$('.selectFunction' + i).show();
		$('body').append('<div id="overlay" style="width:100%; height:100%; top: 0; left: 0; z-index: 499; position: fixed;" onclick="hideOption()"></div>');
	}
	function hideOption(){
		$('.blockFunction').hide();
		$('#overlay').remove();
	}
</script>
